﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caifu.Datas;

namespace Caifu.Clients
{
	/// <summary>
	/// 基金信息操作类。
	/// </summary>
	public static class FundClient
	{
		static string m_CacheKeyPrefix = "Caifu.Fund.";

		/// <summary>
		/// 
		/// </summary>
		/// <param name="fund"></param>
		public static void AddFund(Fund fund)
		{
			FundData.Instance.AddFund(fund);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="fund"></param>
		/// <param name="features"></param>
		public static void AddFund(Fund fund, string[] features)
		{
			FundData.Instance.AddFund(fund, features);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="fund"></param>
		public static void UpdateFund(Fund fund)
		{
			FundData.Instance.UpdateFund(fund);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="fund"></param>
		/// <param name="features"></param>
		public static void UpdateFund(Fund fund, string[] features)
		{
			FundData.Instance.UpdateFund(fund, features);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="id"></param>
		public static void DeleteFund(Guid id)
		{
			FundData.Instance
				.DeleteFund(id);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public static Fund GetFund(Guid id)
		{
			return FundData.Instance
				.GetFund(id);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="fundCode"></param>
		/// <returns></returns>
		public static Fund GetFund(string fundCode)
		{
			return FundData.Instance
				.GetFund(fundCode);
		}

		/// <summary>
		/// 获取所有基金。
		/// 有本地缓存。
		/// </summary>
		/// <returns></returns>
		public static IList<Fund> GetAllFunds()
		{
			var cacheKey = m_CacheKeyPrefix + "AllFunds";
			return CaifuUtil.GetValueFromCache<int, int, IList<Fund>>(cacheKey, FundClient.GetFunds, 1, Int32.MaxValue, CaifuUtil.Cache15Minutes);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<Fund> GetFunds(Int32 pageIndex, Int32 pageSize)
		{
			return FundData.Instance
				.GetFunds(pageIndex, pageSize);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="type"></param>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<Fund> GetFunds(FundType type, Int32 pageIndex, Int32 pageSize)
		{
			return FundData.Instance
				.GetFunds(type, pageIndex, pageSize);
		}

		/// <summary>
		/// 获取指定基金类型的基金。
		/// </summary>
		/// <param name="type">基金类型</param>
		/// <returns></returns>
		public static IList<Fund> GetFunds(FundType type)
		{
			return GetFunds(type, 1, Int32.MaxValue);
		}
	}
}
